package com.dycloud.project.controller.user;

import com.dycloud.project.domain.UserLikeRecord;
import com.dycloud.project.interceptor.annotation.RepeatSubmit;
import com.dycloud.project.service.IUserLikeRecordService;
import com.dycloud.project.service.UserLikeService;
import com.dycloud.project.utils.SecurityUtils;
import com.dycloud.project.web.controller.BaseController;
import com.dycloud.project.web.domain.AjaxResult;
import com.dycloud.project.web.page.TableDataInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : renhang
 * @description UserLikeController
 * @date : 2025-07-02 23:43
 **/
@RestController
@RequestMapping("/user")
public class UserLikeController extends BaseController {


    @Resource
    private UserLikeService userLikeService;

    @Resource
    private IUserLikeRecordService userLikeRecordService;

    /**
     * 点赞
     *
     * @param targetType 点赞目标类型
     * @param id         目标id
     * @param likeStatus 点赞(1)/取消点赞(0)
     * @return: @return {@link AjaxResult }
     */
    @GetMapping("/like")
    @RepeatSubmit(interval = 2000)
    public AjaxResult like(@RequestParam String targetType, @RequestParam Long id, @RequestParam Integer likeStatus) {
        userLikeService.like(targetType, id, likeStatus);
        return AjaxResult.success();
    }


    /**
     * 是否已经点过赞
     *
     * @param targetType targetType
     * @param id         id
     * @return: @return {@link AjaxResult }
     */
    @GetMapping("/getLikeStatus")
    @RepeatSubmit(interval = 2000)
    public AjaxResult getLikeStatus(@RequestParam String targetType, @RequestParam Long id) {
        return AjaxResult.success(userLikeService.getLikeStatus(targetType, id));
    }


    /**
     * 点赞记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserLikeRecord userLikeRecord) {
        startPage();
        // 只能查看自己的点赞记录
        userLikeRecord.setUserId(SecurityUtils.getLoginUser().getUserId());
        List<UserLikeRecord> list = userLikeRecordService.selectUserLikeRecordList(userLikeRecord);
        return getDataTable(list);
    }


}
